package 题目集.贪心;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

//区间越大越好
public class 铺设道路 {
    static int n;
    static int[] nums;

    public static void main(String[] args) throws IOException {
        Reader sc = new Reader();
        n = sc.nextInt();
        nums = new int[n];
        for (int i = 0; i < nums.length; i++) {
            nums[i] = sc.nextInt();
        }
        int res = 0;
        int next = 0;
        while ((next = fun(next)) != -1) {
            res++;
        }
        System.out.println(res);
    }

    /**
     * 清理s以至之后的树，返回第一个!=0的点
     * @return
     */
    public static int fun(int s) {
        int n = -1;
        for (int i = s; i < nums.length; i++) {
            if (n != -1 && nums[i] == 0) {   //碰到非0，且当前是0
                break;
            }
            if (nums[i] != 0) {
                if (n == -1 && nums[i] != 0) {
                    n = i;
                }
                nums[i]--;
            }
        }
        return n;
    }

    static
    class Reader {
        private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer tokenizer = new StringTokenizer("");

        public String next() {
            hasNext();
            return tokenizer.nextToken();
        }

        public String nextLine() {
            String s = null;
            try {
                s = reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }

        public boolean hasNext() {
            if (tokenizer.hasMoreTokens()) {
                return true;
            }
            try {
                tokenizer = new StringTokenizer(reader.readLine());
                return tokenizer.hasMoreTokens();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return false;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
    }

}
